package utils;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author dqthuc
 * 
 */
public class Common {

	public static String makeSuccessXML() {
		return "<root value='true'/>";
	}

	public static String makeErrorXML(String mesage) {
		return "<root value='false' msg=\"" + mesage + "\"/>";
	}

	/**
	 * <br/>
	 * [ Function ] Method print <br/>
	 * [ Description ] Print content string to screen with zip.
	 * 
	 * @param Response
	 * @param content
	 * @return file bean
	 */

	/**
	 * <br/>
	 * [ Function ] Method print <br/>
	 * [ Description ] Print content string to client.
	 * 
	 * @param resp
	 * @param content
	 */
	public static final void print(HttpServletResponse response,
			String content, String contentType, boolean cache) {
		try {
			response.setContentType(contentType);
			// if (!cache)
			response.setHeader("Cache-Control", "no-cache");
			response.getWriter().print(content);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static String makeSuccessXML(String content) {
		return "<root value='true'>" + content + "</root>";
	}

	public static String getTable(String country) {
		// bizdirectory_vn
		// bizdirectory_us
		// bizdirectory_ca
		// bizdirectory_au

		if (country.equalsIgnoreCase("vn")) {
			return "bizdirectory_vn";
		} else if (country.equalsIgnoreCase("ca")) {
			return "bizdirectory_ca";
		} else if (country.equalsIgnoreCase("au")) {
			return "bizdirectory_au";
		} else {
			return "bizdirectory_us";
		}
		// return "directory";
	}

	public static int getTypeSearch(String country) {
		// bizdirectory_vn
		// bizdirectory_us
		// bizdirectory_ca
		// bizdirectory_au
		// public static final int VN =1;
		// public static final int US =2;
		// public static final int CA =3;
		// public static final int AU =4;
		if (country == null) {
			return 1;
		} else if (country.equalsIgnoreCase("us")) {
			return 2;
		} else if (country.equalsIgnoreCase("ca")) {
			return 3;
		} else if (country.equalsIgnoreCase("au")) {
			return 4;
		} else {
			return 1;
		}
	}

	public static String getColumnName(String comnlumName, String lang) {
		String result = comnlumName;
		if (lang.equals("en")) {
			result = result + "_en";
		}
		return result;
	}

}
